<template>
    <div class="common-layout">
        <el-container>
            <el-header style="height: 350px;">
                <img :src="form.coverImg" width="200" height="200" style="float: left;">
                <table style="float: left;margin-left: 50px;">
                    <tr>
                        <td colspan="2">
                            <span style="font-weight: bolder;font-size:larger">{{ form.goodInfoName }}</span>
                        </td>
                    </tr>
                    <br>
                    <tr>
                        <td>
                            生产批次:{{ form.productionBatches }}
                        </td>
                        &nbsp;
                        <td>
                            保质期:{{ form.shelfLife }}天
                        </td>
                    </tr>
                    <br>
                    <tr>
                        <td>
                            生产许可证号:{{ form.productionLicenseCode }}
                        </td>
                        &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
                        <td>
                            生产企业:{{ form.manufacturers }}
                        </td>
                    </tr>
                    <br>
                    <tr>
                        <td colspan="2">
                            <span style="font-weight: bolder;">产品检验报告</span>
                            <el-upload v-model:file-list="simageList"
                                action="http://localhost:24364/api/Traceability/UploadFiles" list-type="picture-card"
                                :on-success="handlePictureCardPreview" :on-remove="handleRemove" :limit="9">
                                <el-icon>
                                    <Plus />
                                </el-icon>
                            </el-upload>
                        </td>
                    </tr>
                </table>
            </el-header>
            <el-main>

                <div>
                    <el-tabs v-model="isShow" class="demo-tabs">
                        <el-tab-pane label="养殖信息(5/5)" :name="0">
                            <span style="font-weight: bolder; color:dodgerblue">养殖信息</span>
                            <el-button style="margin-left: 10px;background-color:aliceblue" size="small"
                                @click="showYangInfo()">设置</el-button>
                            <table style="width: 500px;">
                                <tr>
                                    <td>品种:{{ cultivation.variety }}</td>
                                    <td>来源:{{ cultivation.source }}</td>
                                </tr>
                                <tr>
                                    <td>饲养天数:{{ cultivation.cultivationDay }}</td>
                                    <td>饲料品牌:{{ cultivation.feedBrands }}</td>
                                </tr>
                                <tr>
                                    <td>饲养负责人:{{ cultivation.cultivationHead }}</td>
                                    <td>出栏日期: <span
                                            v-if="cultivation.chuLanDate == null ? '' : cultivation.chuLanDate">{{cultivation.chuLanDate.substring(0, 10) }}</span> </td>
                                </tr>
                            </table>
                            <span style="font-weight: bolder; color:dodgerblue">保健信息</span>
                            <el-button style="margin-left: 10px;background-color:aliceblue" size="small"
                                @click="addDomain">新增行</el-button>
                            <!-- 保健显示 -->
                            <el-table :data="healthCareList" style="width: 100%">
                                <el-table-column prop="cultivationDay" label="饲养天数" />
                                <el-table-column prop="healthCareMethod" label="保健方式" />
                                <el-table-column prop="healthCareType" label="保健方法" />
                                <el-table-column label="操作">
                                    <template v-slot="scope">
                                        <el-button link
                                            @click="showUpdHealthCare(scope.row.healthCareId)">修改</el-button>
                                        <el-button link @click="delHealthCare(scope.row)">删除</el-button>
                                    </template>
                                </el-table-column>
                            </el-table>
                            <!-- <table style="width: 700px;">
                                <tr v-for="(item, index) in healthCareList" :key="index">
                                    <td>
                                        <span v-if="index1 !== index">{{ item.cultivationDay }}</span>
                                        <el-input v-else v-model="healthCare.cultivationDay"  style="width: 100px;margin-right: 30px;"/>
                                    </td>
                                    <td>
                                        <span v-if="index1 !== index">{{ item.healthCareMethod }}</span>
                                        <el-input v-else v-model="healthCare.healthCareMethod"  style="width: 100px;margin-right: 30px;"/>
                                    </td>
                                    <td>
                                        <span v-if="index1 !== index">{{ item.healthCareType }}</span>
                                        <el-input v-else v-model="healthCare.healthCareType" style="width: 100px;margin-right: 30px;"/>
                                    </td>
                                    <td>
                                        <el-button @click="editRow(index);showUpdHealthCare(item.healthCareId)" v-if="index1 !== index" link>修改</el-button>
                                        <el-button @click="delHealthCare(item)" v-if="index1 !== index" link>删除</el-button>
                                        <el-button-group v-else>
                                            <el-button link style="margin-right:15px" @click="updateHeal" >保存</el-button>
                                            <el-button link  @click="cancelEdit(index)" >取消</el-button>
                                        </el-button-group>
                                    </td>
                                </tr>
                            </table> -->
                            <!-- 保健新增行 -->
                            <el-form-item v-for="item in healthCare.healthCareArray">
                                <el-input v-model="item.cultivationDay" style="width: 100px;margin-right: 30px;" />
                                <el-input v-model="item.healthCareMethod" style="width: 100px;margin-right: 30px;" />
                                <el-input v-model="item.healthCareType" style="width: 100px;margin-right: 30px;" />
                                <el-button type="primary" link @click="addHealthCare(item, ruleFormRef)">保存</el-button>
                                <el-button type="primary" link @click.prevent="removeDomain(item)">取消</el-button>
                            </el-form-item>


                            <span style="font-weight: bolder; color:dodgerblue">动检证</span>
                            <el-upload v-model:file-list="dyimageList"
                                action="http://localhost:24364/api/Traceability/UploadFiles" list-type="picture-card"
                                :on-success="handlePictureCardPreviewDY" :on-remove="handleRemove" :limit="9">
                                <el-icon>
                                    <Plus />
                                </el-icon>
                            </el-upload>
                            <span style="font-weight: bolder; color:dodgerblue">企业信息</span>
                            <el-button style="margin-left: 10px;background-color:aliceblue" size="small"
                                @click="showAdd()">设置</el-button>
                            <table style="width: 500px;">
                                <tr>
                                    <td>
                                        养殖场:{{ enterprise.farms }}
                                    </td>
                                    <td>
                                        负责人:{{ enterprise.head }}
                                    </td>
                                </tr>
                                <tr>
                                    <td>
                                        存栏数量:{{ enterprise.herdsNum }}只
                                    </td>
                                    <td></td>
                                </tr>
                            </table>

                        </el-tab-pane>
                        <el-tab-pane label="屠宰信息(5/5)" :name="1">
                            <table style="width: 100%;">
                                <tr>
                                    <span style="font-weight: bolder; color:dodgerblue">屠宰信息</span>
                                    <el-button style="margin-left: 10px;background-color:aliceblue" size="small"
                                        @click="showSlaughterAdd">设置</el-button>
                                </tr>
                                <tr>
                                    <table style="width: 700px;">
                                        <tr>
                                            <td>批次:{{ slaughter.productionBatches }}</td>
                                            <td>到场均重:{{ slaughter.avgWeight }}</td>
                                        </tr>
                                        <tr>
                                            <td>
                                                到场时间:{{ slaughter.presentTime.substring(0, 19).replace("-","年").replace("-", "月").replace("T","日") }}
                                            </td>
                                            <td>
                                                屠宰时间:{{ slaughter.slaughterTime.substring(0, 19).replace("-","年").replace("-","月").replace("T", "日 ") }}
                                            </td>
                                        </tr>
                                    </table>
                                </tr>
                                <tr>
                                    <span style="font-weight: bolder; color:dodgerblue">相关资质</span>
                                    <el-upload v-model:file-list="zTImageList"
                                        action="http://localhost:24364/api/Traceability/UploadFiles"
                                        list-type="picture-card" :on-success="handlePictureCardPreviewZT"
                                        :on-remove="handleRemove" :limit="9">
                                        <el-icon>
                                            <Plus />
                                        </el-icon>
                                    </el-upload>
                                </tr>
                                <tr>
                                    <span style="font-weight: bolder; color:dodgerblue">企业信息</span>
                                    <el-button style="margin-left: 10px;background-color:aliceblue" size="small"
                                        @click="showupdEnter">设置</el-button>
                                </tr>
                                <tr>
                                    <table>
                                        <tr>
                                            <td>
                                                公司名称:{{ enterprise.enterpriseName }}
                                            </td>
                                            <td>
                                                成立时间: <span
                                                    v-if="enterprise.tuZaiDate == null ? '' : enterprise.tuZaiDate">{{enterprise.tuZaiDate.substring(0,10).replace("-", "年").replace("-", "月") }}日</span>
                                            </td>
                                        </tr>
                                        <tr>
                                            <td>
                                                公司地址:{{ enterprise.provinceName }}&nbsp;&nbsp;{{enterprise.cityName }}&nbsp;&nbsp;{{ enterprise.countyName }}
                                            </td>
                                            <td></td>
                                        </tr>
                                        <tr>
                                            <td>
                                                公司简介:{{ enterprise.companyProfile }}
                                            </td>
                                            <td></td>
                                        </tr>
                                    </table>
                                </tr>
                            </table>
                        </el-tab-pane>
                        <el-tab-pane label="深加工信息(0/5)" :name="2">
                            <table>
                                <tr>
                                    <span style="font-weight: bolder; color:dodgerblue">深加工信息</span>
                                    <el-button style="margin-left: 10px;background-color:aliceblue" size="small"
                                        @click="showProcessing">设置</el-button>
                                </tr>
                                <tr>
                                    <table style="width: 500px;">
                                        <tr>
                                            <td>班组:{{ processing.team }}</td>
                                            <td>负责人:{{ processing.head }}</td>
                                        </tr>
                                    </table>
                                </tr>
                                <tr>
                                    <span style="font-weight: bolder; color:dodgerblue">食品安全信息</span>
                                    <el-upload v-model:file-list="PSimageList"
                                        action="http://localhost:24364/api/Traceability/UploadFiles"
                                        list-type="picture-card" :on-success="handlePictureCardPreviewProcessing"
                                        :on-remove="handleRemove" :limit="9">
                                        <el-icon>
                                            <Plus />
                                        </el-icon>
                                    </el-upload>
                                </tr>
                                <tr>
                                    <span style="font-weight: bolder; color:dodgerblue">供应商信息</span>
                                </tr>
                                <tr>
                                    <table>
                                        <tr>
                                            <table>
                                                <tr>
                                                    <span style="font-weight: bolder;">原料</span>
                                                    <el-button style="margin-left: 10px;background-color:aliceblue"
                                                        size="small" @click="showRawmaterial">设置</el-button>
                                                </tr>
                                                <tr>
                                                    生产批次:{{ rawmaterial.rawmaterialProductionBatches }}
                                                </tr>
                                                <tr>
                                                    相关材料
                                                    <el-upload v-model:file-list="rYimageList"
                                                        action="http://localhost:24364/api/Traceability/UploadFiles"
                                                        list-type="picture-card"
                                                        :on-success="handlePictureCardPreviewRY"
                                                        :on-remove="handleRemove" :limit="9">
                                                        <el-icon>
                                                            <Plus />
                                                        </el-icon>
                                                    </el-upload>
                                                </tr>
                                            </table>
                                        </tr>
                                        <tr>
                                            <table>
                                                <tr>
                                                    <span style="font-weight: bolder;">辅料</span>
                                                    <el-button style="margin-left: 10px;background-color:aliceblue"
                                                        size="small" @click="showAccessories">设置</el-button>
                                                </tr>
                                                <tr>
                                                    生产批次:{{ accessories.accessOriesProductionBatches }}
                                                </tr>
                                                <tr>
                                                    相关材料 <el-upload v-model:file-list="aFimageList"
                                                        action="http://localhost:24364/api/Traceability/UploadFiles"
                                                        list-type="picture-card"
                                                        :on-success="handlePictureCardPreviewAF"
                                                        :on-remove="handleRemove" :limit="9">
                                                        <el-icon>
                                                            <Plus />
                                                        </el-icon>
                                                    </el-upload>
                                                </tr>
                                            </table>
                                        </tr>
                                        <tr>
                                            <table>
                                                <tr>
                                                    <span style="font-weight: bolder;">添加剂</span>
                                                    <el-button style="margin-left: 10px;background-color:aliceblue"
                                                        size="small" @click="showAdditive">设置</el-button>
                                                </tr>
                                                <tr>
                                                    生产批次:{{ additive.additiveProductionBatches }}
                                                </tr>
                                                <tr>
                                                    相关材料<el-upload v-model:file-list="aTimageList"
                                                        action="http://localhost:24364/api/Traceability/UploadFiles"
                                                        list-type="picture-card"
                                                        :on-success="handlePictureCardPreviewAT"
                                                        :on-remove="handleRemove" :limit="9">
                                                        <el-icon>
                                                            <Plus />
                                                        </el-icon>
                                                    </el-upload>
                                                </tr>
                                            </table>
                                        </tr>
                                        <tr>
                                            <table>
                                                <tr>
                                                    <span style="font-weight: bolder;">包材</span>
                                                    <el-button style="margin-left: 10px;background-color:aliceblue"
                                                        size="small" @click="showPackagingmaterials">设置</el-button>
                                                </tr>
                                                <tr>
                                                    生产批次:{{ packagingmaterials.packagingmaterialsProductionBatches }}
                                                </tr>
                                                <tr>
                                                    相关材料<el-upload v-model:file-list="bPimageList"
                                                        action="http://localhost:24364/api/Traceability/UploadFiles"
                                                        list-type="picture-card"
                                                        :on-success="handlePictureCardPreviewBP"
                                                        :on-remove="handleRemove" :limit="9">
                                                        <el-icon>
                                                            <Plus />
                                                        </el-icon>
                                                    </el-upload>
                                                </tr>
                                            </table>
                                        </tr>
                                    </table>
                                </tr>
                                <tr>
                                    <span style="font-weight: bolder; color:dodgerblue">企业信息</span>
                                    <el-button style="margin-left: 10px;background-color:aliceblue" size="small"
                                        @click="showupdEnter1">设置</el-button>
                                </tr>
                                <tr>
                                    <table style="width: 500px;">
                                        <tr>
                                            <td>
                                                公司名称:{{ enterprise.enterpriseName }}
                                            </td>
                                            <td>
                                                生产许可证号:{{ enterprise.productionLicenseCode }}
                                            </td>
                                        </tr>
                                    </table>
                                </tr>
                            </table>
                        </el-tab-pane>
                        <span style="font-weight: bolder; color:dodgerblue">企业照片</span>
                        <el-upload v-model:file-list="qeimageList"
                            action="http://localhost:24364/api/Traceability/UploadFiles" list-type="picture-card"
                            :on-success="handlePictureCardPreviewQe" :on-remove="handleRemove" :limit="9">
                            <el-icon>
                                <Plus />
                            </el-icon>
                        </el-upload>
                    </el-tabs>
                </div>
            </el-main>
        </el-container>
    </div>

    <!-- ----------------------------------------------------------养殖信息对话框--------------------------------------------------------------------- -->
    <!-- -------------------养殖信息对话框--------------------->
    <el-dialog v-model="dialogFormVisible" title="养殖信息" width="500">
        <el-form :model="cultivation" ref="ruleFormRef" :rules="rules">
            <el-form-item label="品种" prop="variety">
                <el-input v-model="cultivation.variety" />
            </el-form-item>
            <el-form-item label="来源" prop="source">
                <el-input v-model="cultivation.source" />
            </el-form-item>
            <el-form-item label="饲养天数" prop="cultivationDay">
                <el-input v-model.number="cultivation.cultivationDay" />
            </el-form-item>
            <el-form-item label="饲料品牌" prop="feedBrands">
                <el-input v-model="cultivation.feedBrands" />
            </el-form-item>
            <el-form-item label="饲养负责人" prop="cultivationHead">
                <el-input v-model="cultivation.cultivationHead" />
            </el-form-item>
            <el-form-item label="出栏日期" prop="slaughterDate">
                <el-date-picker v-model="cultivation.slaughterDate" type="date" format="YYYY-MM-DD" placeholder="请选择日期"
                    style="width: 100%" />
            </el-form-item>
        </el-form>
        <template #footer>
            <div class="dialog-footer">
                <el-button v-if="cultivation.variety == ''" type="primary" @click="addInfo(ruleFormRef)">保存</el-button>
                <el-button v-else type="primary" @click="updInfo()">修改</el-button>
            </div>
        </template>
    </el-dialog>
    <!-- -------------------------------修改保健信息---------------------------------------- -->
    <el-dialog v-model="updHealthCare" title="保健信息" width="500">
        <el-form :model="form" ref="ruleFormRef">
            <el-form-item label="饲养天数">
                <el-input v-model.number="healthCare.cultivationDay" />
            </el-form-item>
            <el-form-item label="保健方式">
                <el-input v-model="healthCare.healthCareMethod" />
            </el-form-item>
            <el-form-item label="保健方法">
                <el-input v-model="healthCare.healthCareType" />
            </el-form-item>
        </el-form>
        <template #footer>
            <div class="dialog-footer">
                <el-button type="primary" @click="updateHeal()">
                    保存
                </el-button>
            </div>
        </template>
    </el-dialog>

    <!-- 企业信息对话框(养殖) -->
    <el-dialog v-model="dialogFormVisible1" title="企业信息" width="500">
        <el-form :model="form" ref="ruleFormRef" :rules="rules8">
            <el-form-item label="养殖场" prop="farms">
                <el-input v-model="enterprise.farms" />
            </el-form-item>
            <el-form-item label="负责人" prop="head">
                <el-input v-model="enterprise.head" />
            </el-form-item>
            <el-form-item label="存栏数量(只)" prop="herdsNum">
                <el-input v-model.number="enterprise.herdsNum" />
            </el-form-item>
        </el-form>
        <template #footer>
            <div class="dialog-footer">
                <el-button type="primary" @click="addEnterprise(ruleFormRef)">
                    保存
                </el-button>
            </div>
        </template>
    </el-dialog>
    <!-- -----------------------------------------------------------------屠宰信息对话框--------------------------------------------------------------------------------------- -->
    <el-dialog v-model="dialogFormVisibleSlaughter" title="屠宰信息" width="500">
        <el-form :model="slaughter" ref="ruleFormRef" :rules="rules2">
            <el-form-item label="批次:" prop="productionBatches">
                <el-input v-model="slaughter.productionBatches" />
            </el-form-item>
            <el-form-item label="到场均重(公斤):" prop="avgWeight">
                <el-input v-model.number="slaughter.avgWeight" />
            </el-form-item>
            <el-form-item label="到厂时间" prop="presentTime">
                <el-date-picker v-model="slaughter.presentTime" type="datetime" value-format="YYYY-MM-DDTHH:mm:ss"
                    placeholder="请选择日期" style="width: 100%" />
            </el-form-item>
            <el-form-item label="屠宰时间" prop="slaughterTime">
                <el-date-picker v-model="slaughter.slaughterTime" type="datetime" value-format="YYYY-MM-DDTHH:mm:ss"
                    placeholder="请选择日期" style="width: 100%" />
            </el-form-item>
        </el-form>
        <template #footer>
            <div class="dialog-footer">
                <el-button v-if="slaughter.productionBatches == ''" type="primary"
                    @click="addSlaughter(ruleFormRef)">保存</el-button>
                <el-button v-else type="primary" @click="updSlaughter()">修改</el-button>
            </div>
        </template>
    </el-dialog>
    <!-- 企业信息对话框(屠宰) -->
    <el-dialog v-model="dialogFormVisibleSlaughterUpdEnter1" title="企业信息" width="500">
        <el-form :model="slaughter" ref="ruleFormRef" :rules="rules9">
            <el-form-item label="公司名称:" prop="enterpriseName">
                <el-input v-model="enterprise.enterpriseName" />
            </el-form-item>
            <el-form-item label="公司地址:" prop="countyId">
                <el-select v-model="enterprise.provinceId" style="width: 120px;" placeholder="请选择"
                    @change="getCityList(); getCountyList()" clearable>
                    <el-option v-for="item in provinceList" :label="item.provinceName" :value="item.provinceId"
                        :key="item.provinceId" />
                </el-select>&nbsp;&nbsp;&nbsp;&nbsp;

                <el-select v-model="enterprise.cityId" style="width: 120px;" placeholder="请选择" @change="getCountyList()"
                    clearable>
                    <el-option v-for="item in cityList" :label="item.cityName" :value="item.cityId"
                        :key="item.cityId" />
                </el-select>&nbsp;&nbsp;&nbsp;&nbsp;

                <el-select v-model="enterprise.countyId" style="width: 120px;" placeholder="请选择" clearable>
                    <el-option v-for="item in countyList" :label="item.countyName" :value="item.countyId"
                        :key="item.countyId" />
                </el-select>
            </el-form-item>
            <el-form-item label="成立时间" prop="founded">
                <el-date-picker v-model="enterprise.founded" type="date" placeholder="请选择日期" style="width: 100%" />
            </el-form-item>
            <el-form-item label="公司简介" prop="companyProfile">
                <el-input v-model="enterprise.companyProfile" type="textarea" />
            </el-form-item>
        </el-form>
        <template #footer>
            <div class="dialog-footer">
                <el-button type="primary" @click="updEnter(ruleFormRef)">
                    保存
                </el-button>
            </div>
        </template>
    </el-dialog>
    <!-- -----------------------------------------------------------深加工信息对话框-------------------------------------------------------------------------------------------- -->
    <el-dialog v-model="dialogFormVisibleProcessing" title="深加工信息" width="500">
        <el-form :model="slaughter" ref="ruleFormRef" :rules="rules3">
            <el-form-item label="班组:" prop="team">
                <el-input v-model="processing.team" />
            </el-form-item>
            <el-form-item label="负责人:" prop="head">
                <el-input v-model="processing.head" />
            </el-form-item>
        </el-form>
        <template #footer>
            <div class="dialog-footer">
                <el-button v-if="processing.team == ''" type="primary"
                    @click="addProcessing(ruleFormRef)">保存</el-button>
                <el-button v-else type="primary" @click="updProcessing()">修改</el-button>
            </div>
        </template>
    </el-dialog>
    <el-dialog v-model="dialogFormVisibleRawmaterial" title="原料信息" width="500">
        <el-form :model="slaughter" ref="ruleFormRef" :rules="rules4">
            <el-form-item label="生产批次:" prop="rawmaterialProductionBatches">
                <el-input v-model="rawmaterial.rawmaterialProductionBatches" />
            </el-form-item>
        </el-form>
        <template #footer>
            <div class="dialog-footer">
                <el-button v-if="rawmaterial.rawmaterialProductionBatches == ''" type="primary"
                    @click="addRawmaterial(ruleFormRef)">保存</el-button>
                <el-button v-else type="primary" @click="updRawmaterial()">修改</el-button>
            </div>
        </template>
    </el-dialog>
    <el-dialog v-model="dialogFormVisibleAccessories" title="辅料信息" width="500">
        <el-form :model="slaughter" ref="ruleFormRef" :rules="rules5">
            <el-form-item label="生产批次:" prop="accessOriesProductionBatches">
                <el-input v-model="accessories.accessOriesProductionBatches" />
            </el-form-item>
        </el-form>
        <template #footer>
            <div class="dialog-footer">
                <el-button v-if="accessories.accessOriesProductionBatches == ''" type="primary"
                    @click="addAccessories(ruleFormRef)">保存</el-button>
                <el-button v-else type="primary" @click="updAccessories()">修改</el-button>
            </div>
        </template>
    </el-dialog>
    <el-dialog v-model="dialogFormVisibleAdditive" title="添加剂信息" width="500">
        <el-form :model="slaughter" ref="ruleFormRef" :rules="rules6">
            <el-form-item label="生产批次:" prop="additiveProductionBatches">
                <el-input v-model="additive.additiveProductionBatches" />
            </el-form-item>
        </el-form>
        <template #footer>
            <div class="dialog-footer">
                <el-button v-if="additive.additiveProductionBatches == ''" type="primary"
                    @click="addAdditive(ruleFormRef)">保存</el-button>
                <el-button v-else type="primary" @click="updAdditive()">修改</el-button>
            </div>
        </template>
    </el-dialog>
    <el-dialog v-model="dialogFormVisiblePackagingmaterials" title="包材信息" width="500">
        <el-form :model="slaughter" ref="ruleFormRef" :rules="rules7">
            <el-form-item label="生产批次:" prop="packagingmaterialsProductionBatches">
                <el-input v-model="packagingmaterials.packagingmaterialsProductionBatches" />
            </el-form-item>
        </el-form>
        <template #footer>
            <div class="dialog-footer">
                <el-button v-if="packagingmaterials.packagingmaterialsProductionBatches == ''" type="primary"
                    @click="addPackagingmaterials(ruleFormRef)">保存</el-button>
                <el-button v-else type="primary" @click="updPackagingmaterials()">修改</el-button>
            </div>
        </template>
    </el-dialog>
    <el-dialog v-model="dialogFormVisibleSlaughterUpdEnter2" title="企业信息" width="500">
        <el-form :model="slaughter" ref="ruleFormRef" :rules="rules10">
            <el-form-item label="公司名称:" prop="enterpriseName">
                <el-input v-model="enterprise.enterpriseName" />
            </el-form-item>
            <el-form-item label="生产许可证号:" prop="productionLicenseCode">
                <el-input v-model="enterprise.productionLicenseCode" />
            </el-form-item>
        </el-form>
        <template #footer>
            <div class="dialog-footer">
                <el-button type="primary" @click="updEnter1(ruleFormRef)">
                    保存
                </el-button>
            </div>
        </template>
    </el-dialog>



</template>

<script setup lang="ts">
// const index1 = ref(-1);
// const editRow = (index: any) => {
//     index1.value = index;
// };
import { ref, reactive, onMounted } from 'vue'
import axios from 'axios'
import { useRoute, useRouter } from 'vue-router';
import { ElMessage, ElMessageBox } from 'element-plus';
import type { UploadProps } from 'element-plus'
import { Plus } from '@element-plus/icons-vue'
const route = useRoute();
const router = useRouter();
const form = reactive({
    traceabilityId: route.query.traceabilityId,
    goodInfoName: "",
    productionBatches: route.query.productionBatches,
    shelfLife: '',
    productionLicenseCode: "",
    manufacturers: "",
    coverImg: "",
    createName: localStorage.getItem("userName"),
    createTime: new Date(),
    updateName: localStorage.getItem("userName"),
    updateTime: new Date(),
})

//#region 弹框显示字段
const isShow = ref(0);
const dialogFormVisible = ref(false);//添加养殖
const dialogFormVisible1 = ref(false);//添加企业(养殖)
const updHealthCare = ref(false);//修改保健
const dialogFormVisibleSlaughter = ref(false);//添加屠宰
const dialogFormVisibleSlaughterUpdEnter1 = ref(false);//修改企业(屠宰)
const dialogFormVisibleProcessing = ref(false);//添加深加工
const dialogFormVisibleRawmaterial = ref(false);//原料
const dialogFormVisibleAccessories = ref(false);//辅料
const dialogFormVisibleAdditive = ref(false);//添加剂
const dialogFormVisiblePackagingmaterials = ref(false);//包材
const dialogFormVisibleSlaughterUpdEnter2 = ref(false);//修改企业(深加工)
//#endregion

//表单校验
import type { ComponentSize, FormInstance, FormRules } from 'element-plus'
const ruleFormRef = ref<FormInstance>()
//返填
const backfill = () => {
    axios.get("/api/Traceability/Backfill", {
        params: {
            ProductionBatches: form.productionBatches,
            TraceabilityId: form.traceabilityId
        }
    })
        .then(res => {
            // form.traceabilityId = res.data.data.traceabilityId
            form.goodInfoName = res.data.data.goodInfoName
            // form.productionBatches = res.data.data.productionBatches
            form.shelfLife = res.data.data.shelfLife
            form.productionLicenseCode = res.data.data.productionLicenseCode
            form.manufacturers = res.data.data.manufacturers
            form.coverImg = res.data.data.coverImg
            form.createName = res.data.data.createName
            form.createTime = res.data.data.createTime
            //返填养殖
            backfillCultivation();
            //显示保健
            getHealthCreaList();
            //显示企业
            showEnterprise();
            //返填企业
            backfillEnterprise();
            //返填产检图片
            getImageList(form.traceabilityId);
            //返填屠宰信息
            backfillSlaughter();
            //返填深加工信息
            backfillProcessing();
            //返填原料信息
            getRawmaterial();
            //返填辅料信息
            getAccessories();
            //返填添加剂
            getAdditive();
            //返填包材
            getPackagingmaterials();
        })
        .catch(err => {
            console.log(err);
        })
}
//#region 养殖信息

//养殖信息
const cultivation = reactive({
    cultivationId: 0,
    variety: "",
    source: "",
    cultivationDay: '',
    feedBrands: "",
    cultivationHead: "",
    slaughterDate: "",
    chuLanDate: "",
    productionBatches: form.productionBatches,
    createName: localStorage.getItem("userName"),
    createTime: new Date(),
    updateName: localStorage.getItem("userName"),
    updateTime: new Date(),
})
//打开养殖信息对话框
const showYangInfo = () => {
    dialogFormVisible.value = true
}
//养殖校验
const rules = reactive<FormRules>({
    variety: [
        { required: true, message: '品种不能为空', trigger: 'blur' },
    ],
    source: [
        {
            required: true,
            message: '来源不能为空',
            trigger: 'blur',
        },
        { min: 0, max: 30, message: '最多输入30位字符', trigger: 'blur' },
    ],
    cultivationDay: [
        {
            required: true,
            message: '饲养天数不能为空',
            trigger: 'blur',
        }, { min: 0, max: 5, message: '最多输入5位数字', trigger: 'blur' },
        { type: 'number', message: "只允许输入数字" }
    ],
    feedBrands: [
        {
            required: true,
            message: '饲料品牌不能为空',
            trigger: 'blur',
        }, { min: 0, max: 30, message: '最多输入30位字符', trigger: 'blur' },
        // { pattern: /^[A-Za-z0-9]$/, message: "只能输入数字和字母", trigger: "blur" }
    ],
    cultivationHead: [
        {
            required: true,
            message: '饲养负责人不能为空',
            trigger: 'blur',
        },
        { min: 0, max: 30, message: '最多输入30位字符', trigger: 'blur' },
        // { pattern: /^[\u4E00-\u9FA5A-Za-z]$ /, message: "允许输入任意字符（主要为中文、字母）", trigger: "blur" }
    ],
    slaughterDate: [
        {
            required: true,
            message: '出栏日期不能为空',
            trigger: 'blur',
        },
    ],
})
//添加养殖信息
const addInfo = async (formEl: FormInstance | undefined) => {
    if (!formEl) return
    await formEl.validate((valid, fields) => {
        if (valid) {
            axios.post("/api/Cultivation/AddCultivation", cultivation)
                .then(res => {
                    if (res.data.code == 0) {
                        ElMessage.success("添加成功");
                        dialogFormVisible.value = false;
                        backfill();
                    }
                })
                .catch(err => {
                    console.log(err);
                })
        } else {
            console.log('error submit!', fields)
        }
    })

}
//返填养殖信息
const backfillCultivation = () => {
    axios.get("/api/Cultivation/GetCultivationFirst", {
        params: {
            ProductionBatches: form.productionBatches
        }
    })
        .then(res => {
            cultivation.cultivationId = res.data.data.cultivationId
            cultivation.variety = res.data.data.variety
            cultivation.source = res.data.data.source
            cultivation.cultivationDay = res.data.data.cultivationDay
            cultivation.feedBrands = res.data.data.feedBrands
            cultivation.cultivationHead = res.data.data.cultivationHead
            cultivation.slaughterDate = res.data.data.slaughterDate
            cultivation.chuLanDate = cultivation.slaughterDate
            dYImage.cultivationId = res.data.data.cultivationId
            //返填动产证图片
            getDyImageList();
        })
        .catch(err => {
            console.log(err);
        })
}
//修改养殖
const updInfo = () => {
    axios.post("/api/Cultivation/Update", cultivation)
        .then(res => {
            if (res.data.code == 0) {
                ElMessage.success("修改成功");
                dialogFormVisible.value = false;
                backfill();
            }
        })
        .catch(err => {
            console.log(err);
        })
}

//保健信息
const healthCare: any = reactive({
    healthCareArray: [
        {
            healthCareId: '',
            cultivationDay: '',
            healthCareType: "",
            healthCareMethod: "",
            productionBatches: form.productionBatches,
            createName: localStorage.getItem("userName"),
            createTime: new Date(),
            updateName: localStorage.getItem("userName"),
            updateTime: new Date(),
        }
    ]
});
//新增行
const addDomain = () => {
    healthCare.healthCareArray.push({
        healthCareId: '',
        cultivationDay: '',
        healthCareType: "",
        healthCareMethod: "",
        productionBatches: form.productionBatches,
        createName: localStorage.getItem("userName"),
        createTime: new Date(),
        updateName: localStorage.getItem("userName"),
        updateTime: new Date(),
    })
}
//取消新增行
const removeDomain = (item: any) => {
    const index = healthCare.healthCareArray.indexOf(item)
    if (index !== -1) {
        healthCare.healthCareArray.splice(index, 1)
    }
}
//保健校验
// const rules1 = reactive<FormRules>({
//     cultivationDay: [
//         {required: true,message: '饲养天数不能为空',trigger: 'blur',}, { min: 0, max: 5, message: '最多输入5位数字', trigger: 'blur' },
//         { type: 'number', message: "只允许输入数字" }
//     ],
//     healthCareMethod: [
//         {required: true,message: '保健方式不能为空',trigger: 'blur',},
//         { min: 0, max: 30, message: '最多输入30位字符', trigger: 'blur' },
//     ],
//     healthCareType: [
//         {required: true,message: '保健方法不能为空',trigger: 'blur',}, 
//         { min: 0, max: 30, message: '最多输入30位字符', trigger: 'blur' },
//         // { pattern: /^[A-Za-z0-9]$/, message: "只能输入数字和字母", trigger: "blur" }
//     ],
// })
//添加保健信息
const addHealthCare = (item: any) => {
    axios.post("/api/HealthCare/Create", item)
        .then(res => {
            if (res.data.code == 0) {
                ElMessage.success("添加成功");
                getHealthCreaList();
            }
        })
        .catch(err => {
            console.log(err);
        })
}
//保健信息显示
const healthCareList = ref([])
const getHealthCreaList = () => {
    axios.get('/api/HealthCare/Show', {
        params: {
            ProductionBatches: form.productionBatches
        }
    })
        .then(res => {
            healthCareList.value = res.data.data
            // console.log(healthCare.healthCareMethod)
        })
        .catch(err => {
            console.log(err);
        })
}
//删除保健信息
const delHealthCare = (row: any) => {

    ElMessageBox.confirm(
        '确定要删除吗?',
        '警告',
        {
            confirmButtonText: '确认',
            cancelButtonText: '取消',
            type: 'warning',
        }
    )
        .then(() => {
            axios.post("/api/HealthCare/Delete", row)
                .then(res => {
                    if (res.data.code == 0) {
                        ElMessage.success("删除成功");
                        getHealthCreaList();
                    }
                })
                .catch(err => {
                    console.log(err);
                })
        })
        .catch(() => {
            ElMessage({
                type: 'info',
                message: '已取消该操作',
            })
        })
}
//打开修改保健信息对话框
const showUpdHealthCare = (healthCareId: any) => {
    updHealthCare.value = true;
    backfillHealthCare(healthCareId);
}
//返填保健信息
const backfillHealthCare = (healthCareId: any) => {
    axios.get("/api/HealthCare/GetAllHealthCareById?HealthCareId=" + healthCareId)
        .then(res => {
            healthCare.healthCareId = res.data.data.healthCareId
            healthCare.cultivationDay = res.data.data.cultivationDay
            healthCare.healthCareType = res.data.data.healthCareType
            healthCare.healthCareMethod = res.data.data.healthCareMethod
            healthCare.productionBatches = res.data.data.productionBatches
            healthCare.createName = res.data.data.createName
            healthCare.createTime = res.data.data.createTime
            healthCare.updateName = res.data.data.updateName
            healthCare.updateTime = res.data.data.updateTime
        })
        .catch(err => {
            console.log(err);
        })
}
//修改保健信息
const updateHeal = () => {
    axios.post("/api/HealthCare/Update", healthCare)
        .then(res => {
            if (res.data.code == 0) {
                ElMessage.success("修改成功");
                updHealthCare.value = false;
                getHealthCreaList();
            }
        })
        .catch(err => {
            console.log(err);
        })
}
//取消修改保健
// const cancelEdit = (index) => {
//     healthCareList.value[index].isEditing = false;
// };
//添加动产证图片
const dYImage = reactive({
    imageUrl: "",
    productionBatches: form.productionBatches,
    // traceabilityId: form.traceabilityId,
    cultivationId: '',
    // slaughterId: '',
    // processingId: '',
    // rawmaterialId: '',
    // accessoriesId: '',
    // additiveId: '',
    // packagingmaterialsId: '',
    createName: localStorage.getItem("userName"),
    createTime: new Date(),
})
const handlePictureCardPreviewDY = (url: any) => {
    // console.log(cultivation.cultivationId)
    // console.log(dYImage.cultivationId)
    dYImage.imageUrl = "http://localhost:24364" + url;
    axios.post("/api/Image/Create", dYImage)
        .then(res => {
            if (res.data.data == 1) {
                ElMessage.success("上传成功");
            }
        })
        .catch(err => {
            console.log(err);
        })
}
//显示动产证图片
const dyimageList = ref([])
const getDyImageList = () => {
    axios.get("/api/Image/GetDYImages?CultivationId=" + cultivation.cultivationId)
        .then(res => {
            dyimageList.value = res.data.data
        })
        .catch(err => {
            console.log(err);
        })
}
//#endregion

//#region 屠宰信息
const slaughter = reactive({
    slaughterId: 0,
    productionBatches: form.productionBatches,
    avgWeight: '',
    presentTime: "",
    slaughterTime: "",
    createName: localStorage.getItem("userName"),
    createTime: new Date(),
    updateName: localStorage.getItem("userName"),
    updateTime: new Date(),
})
//显示屠宰弹框信息
const showSlaughterAdd = () => {
    dialogFormVisibleSlaughter.value = true;
}
//屠宰校验
const rules2 = reactive<FormRules>({
    productionBatches: [
        { required: true, message: '保健方式不能为空', trigger: 'blur', },
        { min: 0, max: 30, message: '最多输入30位字符', trigger: 'blur' },
    ],
    avgWeight: [
        { required: true, message: '到场均重不能为空', trigger: 'blur', },
        { min: 0, max: 5, message: '最多输入5位数字', trigger: 'blur' },
        { type: 'number', message: "只允许输入数字" }
    ],
    presentTime: [
        { required: true, message: '到场时间不能为空', trigger: 'blur', },
        // { min: 0, max: 30, message: '最多输入30位字符', trigger: 'blur' },
        // { pattern: /^[A-Za-z0-9]$/, message: "只能输入数字和字母", trigger: "blur" }
    ],
    slaughterTime: [
        { required: true, message: '屠宰时间不能为空', trigger: 'blur', },
        // { min: 0, max: 30, message: '最多输入30位字符', trigger: 'blur' },
        // { pattern: /^[A-Za-z0-9]$/, message: "只能输入数字和字母", trigger: "blur" }
    ],
})
//添加屠宰信息
const addSlaughter = async (formEl: FormInstance | undefined) => {
    // console.log(slaughter);
    if (!formEl) return
    await formEl.validate((valid, fields) => {
        if (valid) {
            axios.post("/api/Slaughter/Create", slaughter)
                .then(res => {
                    if (res.data.code == 0) {
                        ElMessage.success("添加成功");
                        dialogFormVisibleSlaughter.value = false;
                    }
                })
                .catch(err => {
                    console.log(err);
                })
        } else {
            console.log('error submit!', fields)
        }
    })

}
//返填屠宰信息
const backfillSlaughter = () => {
    axios.get("/api/Slaughter/Show?ProductionBatches=" + form.productionBatches)
        .then(res => {
            slaughter.slaughterId = res.data.data.slaughterId
            slaughter.productionBatches = res.data.data.productionBatches
            slaughter.avgWeight = res.data.data.avgWeight
            slaughter.presentTime = res.data.data.presentTime
            slaughter.slaughterTime = res.data.data.slaughterTime
            slaughter.createName = res.data.data.createName
            slaughter.createTime = res.data.data.createTime
            zTImage.slaughterId = res.data.data.slaughterId
            //返填/显示图片
            getZTImageList();
        })
        .catch(err => {
            console.log(err);
        })
}
//修改屠宰信息
const updSlaughter = () => {
    axios.post("/api/Slaughter/Update", slaughter)
        .then(res => {
            if (res.data.code == 0) {
                ElMessage.success("修改成功");
                dialogFormVisibleSlaughter.value = false;
            }
        })
        .catch(err => {
            console.log(err);
        })
}
//屠宰图片信息
const zTImage = reactive({
    imageUrl: "",
    productionBatches: form.productionBatches,
    // traceabilityId: form.traceabilityId,
    // cultivationId: '',
    slaughterId: '',
    // processingId: '',
    // enterpriseId: '',
    // rawmaterialId: '',
    // accessoriesId: '',
    // additiveId: '',
    // packagingmaterialsId: '',
    createName: localStorage.getItem("userName"),
    createTime: new Date(),
})
//添加屠宰图片
const handlePictureCardPreviewZT = (url: any) => {
    console.log(slaughter.slaughterId)
    console.log(zTImage.slaughterId)
    zTImage.imageUrl = "http://localhost:24364" + url;
    axios.post("/api/Image/Create", zTImage)
        .then(res => {
            if (res.data.data == 1) {
                ElMessage.success("上传成功");
            }
        })
        .catch(err => {
            console.log(err);
        })
}
//显示图片
const zTImageList = ref([])
const getZTImageList = () => {
    // console.log(slaughter.slaughterId)
    axios.get("/api/Image/GetZTImages?SlaughterId=" + slaughter.slaughterId)
        .then(res => {
            zTImageList.value = res.data.data
        })
        .catch(err => {
            console.log(err);
        })
}
//#endregion

//#region 深加工信息
const processing = reactive({
    processingId: 0,
    team: "",
    head: "",
    productionBatches: form.productionBatches,
    createName: localStorage.getItem("userName"),
    createTime: new Date(),
    updateName: localStorage.getItem("userName"),
    updateTime: new Date(),
})
//打开深加工对话框
const showProcessing = () => {
    dialogFormVisibleProcessing.value = true;
}
//深加工校验
const rules3 = reactive<FormRules>({
    team: [
        { required: true, message: '班组不能为空', trigger: 'blur', },
        { min: 0, max: 30, message: '最多输入30位字符', trigger: 'blur' },
    ],
    head: [
        { required: true, message: '负责人不能为空', trigger: 'blur', },
        { min: 0, max: 30, message: '最多输入30位字符', trigger: 'blur' },
    ],
})
//添加深加工
const addProcessing = async (formEl: FormInstance | undefined) => {
    if (!formEl) return
    await formEl.validate((valid, fields) => {
        if (valid) {
            axios.post("/api/Processing/AddProcessing", processing)
                .then(res => {
                    if (res.data.code == 0) {
                        ElMessage.success("添加成功");
                        dialogFormVisibleProcessing.value = false;
                    }
                })
                .catch(err => {
                    console.log(err);
                })
        } else {
            console.log('error submit!', fields)
        }
    })

}
//返填深加工
const backfillProcessing = () => {
    axios.get("/api/Processing/GetProcessing", {
        params: {
            ProductionBatches: form.productionBatches
        }
    })
        .then(res => {
            processing.processingId = res.data.data.processingId
            processing.team = res.data.data.team
            processing.head = res.data.data.head
            processing.productionBatches = res.data.data.productionBatches
            processing.createName = res.data.data.createName
            processing.createTime = res.data.data.createTime
            pSImage.processingId = res.data.data.processingId
            getPSimageList();
        })
        .catch(err => {
            console.log(err);
        })
}
//修改深加工
const updProcessing = () => {
    axios.post("/api/Processing/Update", processing)
        .then(res => {
            if (res.data.code == 0) {
                ElMessage.success("修改成功");
                dialogFormVisibleProcessing.value = false;
            }
        })
        .catch(err => {
            console.log(err);
        })
}
//深加工图片信息
const pSImage = reactive({
    imageUrl: "",
    productionBatches: form.productionBatches,
    // traceabilityId: form.traceabilityId,
    // cultivationId: '',
    // slaughterId: '',
    processingId: '',
    // enterpriseId: '',
    // rawmaterialId: '',
    // accessoriesId: '',
    // additiveId: '',
    // packagingmaterialsId: '',
    createName: localStorage.getItem("userName"),
    createTime: new Date(),
})
//添加深加工图片
const handlePictureCardPreviewProcessing = (url: any) => {
    // console.log(processing.processingId)
    // console.log(pSImage.processingId)
    pSImage.imageUrl = "http://localhost:24364" + url;
    axios.post("/api/Image/Create", pSImage)
        .then(res => {
            if (res.data.data == 1) {
                ElMessage.success("上传成功");
            }
        })
        .catch(err => {
            console.log(err);
        })
}
//返填深加工图片
const PSimageList = ref([])
const getPSimageList = () => {
    // console.log(processing.processingId)
    axios.get("/api/Image/GetASImages?ProcessingId=" + processing.processingId)
        .then(res => {
            PSimageList.value = res.data.data
        })
        .catch(err => {
            console.log(err);
        })
}

//#region 原料
const rawmaterial = reactive({
    rawmaterialId: 0,
    rawmaterialProductionBatches: '',
    productionBatches: form.productionBatches
})
//打开原料对话框
const showRawmaterial = () => {
    dialogFormVisibleRawmaterial.value = true;
}
//原料校验
const rules4 = reactive<FormRules>({
    rawmaterialProductionBatches: [
        { required: true, message: '生产批次不能为空', trigger: 'blur', },
        { min: 0, max: 30, message: '最多输入30位字符', trigger: 'blur' },
    ],
})
//添加原料
const addRawmaterial = async (formEl: FormInstance | undefined) => {
    // console.log(rawmaterial)
    if (!formEl) return
    await formEl.validate((valid, fields) => {
        if (valid) {
            axios.post("/api/Rawmaterial/Create", rawmaterial)
                .then(res => {
                    if (res.data.code == 0) {
                        ElMessage.success("添加成功");
                        dialogFormVisibleRawmaterial.value = false;
                    }
                })
                .catch(err => {
                    console.log(err);
                })
        } else {
            console.log('error submit!', fields)
        }
    })

}
//返填原料
const getRawmaterial = () => {
    axios.get("/api/Rawmaterial/GetRawmaterial", {
        params: {
            ProductionBatches: form.productionBatches
        }
    })
        .then(res => {
            rawmaterial.rawmaterialId = res.data.data.rawmaterialId
            rawmaterial.rawmaterialProductionBatches = res.data.data.rawmaterialProductionBatches
            rawmaterial.productionBatches = res.data.data.productionBatches
            rYImage.rawmaterialId = res.data.data.rawmaterialId
            getRYImageList();
        })
        .catch(err => {
            console.log(err);
        })
}
//修改原料
const updRawmaterial = () => {
    axios.post("/api/Rawmaterial/Update", rawmaterial)
        .then(res => {
            if (res.data.code == 0) {
                ElMessage.success("修改成功");
                dialogFormVisibleRawmaterial.value = false;
            }
        })
        .catch(err => {
            console.log(err);
        })
}
//图片
const rYImage = reactive({
    imageUrl: "",
    productionBatches: form.productionBatches,
    // traceabilityId: form.traceabilityId,
    // cultivationId: '',
    // slaughterId: '',
    // processingId: '',
    // enterpriseId: '',
    rawmaterialId: '',
    // accessoriesId: '',
    // additiveId: '',
    // packagingmaterialsId: '',
    createName: localStorage.getItem("userName"),
    createTime: new Date(),
})
//添加原料图片
const handlePictureCardPreviewRY = (url: any) => {
    // console.log(enterprise.enterpriseId)
    // console.log(qEImage.enterpriseId)
    rYImage.imageUrl = "http://localhost:24364" + url;
    axios.post("/api/Image/Create", rYImage)
        .then(res => {
            if (res.data.data == 1) {
                ElMessage.success("上传成功");
            }
        })
        .catch(err => {
            console.log(err);
        })
}
//显示原料图片
const rYimageList = ref([])
const getRYImageList = () => {
    // console.log(enterprise.enterpriseId)
    axios.get("/api/Image/GetRYImages?RawmaterialId=" + rawmaterial.rawmaterialId)
        .then(res => {
            rYimageList.value = res.data.data
        })
        .catch(err => {
            console.log(err);
        })
}
//#endregion

//#region 辅料
const accessories = reactive({
    accessoriesId: 0,
    accessOriesProductionBatches: '',
    productionBatches: form.productionBatches
})
// //打开辅料对话框
const showAccessories = () => {
    dialogFormVisibleAccessories.value = true;
}
//辅料校验
const rules5 = reactive<FormRules>({
    accessOriesProductionBatches: [
        { required: true, message: '生产批次不能为空', trigger: 'blur', },
        { min: 0, max: 30, message: '最多输入30位字符', trigger: 'blur' },
    ],
})
// //添加辅料
const addAccessories = async (formEl: FormInstance | undefined) => {
    // console.log(accessories)
    if (!formEl) return
    await formEl.validate((valid, fields) => {
        if (valid) {
            axios.post("/api/Accessories/Create", accessories)
                .then(res => {
                    if (res.data.code == 0) {
                        ElMessage.success("添加成功");
                        dialogFormVisibleAccessories.value = false;
                    }
                })
                .catch(err => {
                    console.log(err);
                })
        } else {
            console.log('error submit!', fields)
        }
    })

}
// //返填辅料
const getAccessories = () => {
    axios.get("/api/Accessories/GetAccessories", {
        params: {
            ProductionBatches: form.productionBatches
        }
    })
        .then(res => {
            accessories.accessoriesId = res.data.data.accessoriesId
            accessories.accessOriesProductionBatches = res.data.data.accessOriesProductionBatches
            accessories.productionBatches = res.data.data.productionBatches
            aFImage.accessoriesId = res.data.data.accessoriesId
            getAFImageList();
        })
        .catch(err => {
            console.log(err);
        })
}
//修改辅料
const updAccessories = () => {
    axios.post("/api/Accessories/Update", accessories)
        .then(res => {
            if (res.data.code == 0) {
                ElMessage.success("修改成功");
                dialogFormVisibleAccessories.value = false;
            }
        })
        .catch(err => {
            console.log(err);
        })
}
// //图片
const aFImage = reactive({
    imageUrl: "",
    productionBatches: form.productionBatches,
    // traceabilityId: form.traceabilityId,
    // cultivationId: '',
    // slaughterId: '',
    // processingId: '',
    // enterpriseId: '',
    // rawmaterialId: '',
    accessoriesId: '',
    // additiveId: '',
    // packagingmaterialsId: '',
    createName: localStorage.getItem("userName"),
    createTime: new Date(),
})
// //添加辅料图片
const handlePictureCardPreviewAF = (url: any) => {
    // console.log(enterprise.enterpriseId)
    // console.log(qEImage.enterpriseId)
    aFImage.imageUrl = "http://localhost:24364" + url;
    axios.post("/api/Image/Create", aFImage)
        .then(res => {
            if (res.data.data == 1) {
                ElMessage.success("上传成功");
            }
        })
        .catch(err => {
            console.log(err);
        })
}
// //显示辅料图片
const aFimageList = ref([])
const getAFImageList = () => {
    // console.log(enterprise.enterpriseId)
    axios.get("/api/Image/GetAFImages?AccessoriesId=" + accessories.accessoriesId)
        .then(res => {
            aFimageList.value = res.data.data
        })
        .catch(err => {
            console.log(err);
        })
}
//#endregion

//#region 添加剂
const additive = reactive({
    additiveId: 0,
    additiveProductionBatches: '',
    productionBatches: form.productionBatches
})
// //打开添加剂对话框
const showAdditive = () => {
    dialogFormVisibleAdditive.value = true;
}
//添加剂校验
const rules6 = reactive<FormRules>({
    additiveProductionBatches: [
        { required: true, message: '生产批次不能为空', trigger: 'blur', },
        { min: 0, max: 30, message: '最多输入30位字符', trigger: 'blur' },
    ],
})
//添加添加剂
const addAdditive = async (formEl: FormInstance | undefined) => {
    // console.log(accessories)
    if (!formEl) return
    await formEl.validate((valid, fields) => {
        if (valid) {
            axios.post("/api/Additive/Create", additive)
                .then(res => {
                    if (res.data.code == 0) {
                        ElMessage.success("添加成功");
                        dialogFormVisibleAdditive.value = false;
                    }
                })
                .catch(err => {
                    console.log(err);
                })
        } else {
            console.log('error submit!', fields)
        }
    })

}
//返填添加剂
const getAdditive = () => {
    axios.get("/api/Additive/GetAdditive", {
        params: {
            ProductionBatches: form.productionBatches
        }
    })
        .then(res => {
            additive.additiveId = res.data.data.additiveId
            additive.additiveProductionBatches = res.data.data.additiveProductionBatches
            additive.productionBatches = res.data.data.productionBatches
            aTImage.additiveId = res.data.data.additiveId
            getATImageList();
        })
        .catch(err => {
            console.log(err);
        })
}
//修改添加剂
const updAdditive = () => {
    axios.post("/api/Additive/Update", additive)
        .then(res => {
            if (res.data.code == 0) {
                ElMessage.success("修改成功");
                dialogFormVisibleAdditive.value = false;
            }
        })
        .catch(err => {
            console.log(err);
        })
}
//图片
const aTImage = reactive({
    imageUrl: "",
    productionBatches: form.productionBatches,
    // traceabilityId: form.traceabilityId,
    // cultivationId: '',
    // slaughterId: '',
    // processingId: '',
    // enterpriseId: '',
    // rawmaterialId: '',
    // accessoriesId: '',
    additiveId: '',
    // packagingmaterialsId: '',
    createName: localStorage.getItem("userName"),
    createTime: new Date(),
})
//添加添加剂图片
const handlePictureCardPreviewAT = (url: any) => {
    // console.log(enterprise.enterpriseId)
    // console.log(qEImage.enterpriseId)
    aTImage.imageUrl = "http://localhost:24364" + url;
    axios.post("/api/Image/Create", aTImage)
        .then(res => {
            if (res.data.data == 1) {
                ElMessage.success("上传成功");
            }
        })
        .catch(err => {
            console.log(err);
        })
}
//显示添加剂图片
const aTimageList = ref([])
const getATImageList = () => {
    // console.log(enterprise.enterpriseId)
    axios.get("/api/Image/GetATImages?AdditiveId=" + additive.additiveId)
        .then(res => {
            aTimageList.value = res.data.data
        })
        .catch(err => {
            console.log(err);
        })
}
//#endregion

//#region 包材
const packagingmaterials = reactive({
    packagingmaterialsId: 0,
    packagingmaterialsProductionBatches: '',
    productionBatches: form.productionBatches
})
//打开包材对话框
const showPackagingmaterials = () => {
    dialogFormVisiblePackagingmaterials.value = true;
}
//包材校验
const rules7 = reactive<FormRules>({
    packagingmaterialsProductionBatches: [
        { required: true, message: '生产批次不能为空', trigger: 'blur', },
        { min: 0, max: 30, message: '最多输入30位字符', trigger: 'blur' },
    ],
})
//添加包材
const addPackagingmaterials = async (formEl: FormInstance | undefined) => {
    // console.log(accessories)
    if (!formEl) return
    await formEl.validate((valid, fields) => {
        if (valid) {
            axios.post("/api/Packagingmaterials/AddPackagingmaterials", packagingmaterials)
                .then(res => {
                    if (res.data.code == 0) {
                        ElMessage.success("添加成功");
                        dialogFormVisiblePackagingmaterials.value = false;
                    }
                })
                .catch(err => {
                    console.log(err);
                })
        } else {
            console.log('error submit!', fields)
        }
    })

}
//返填包材
const getPackagingmaterials = () => {
    axios.get("/api/Packagingmaterials/GetPackagingmaterials", {
        params: {
            ProductionBatches: form.productionBatches
        }
    })
        .then(res => {
            packagingmaterials.packagingmaterialsId = res.data.data.packagingmaterialsId
            packagingmaterials.packagingmaterialsProductionBatches = res.data.data.packagingmaterialsProductionBatches
            packagingmaterials.productionBatches = res.data.data.productionBatches
            bPImage.packagingmaterialsId = res.data.data.packagingmaterialsId
            getBPImageList();
        })
        .catch(err => {
            console.log(err);
        })
}
//修改包材
const updPackagingmaterials = () => {
    axios.post("/api/Packagingmaterials/Update", packagingmaterials)
        .then(res => {
            if (res.data.code == 0) {
                ElMessage.success("修改成功");
                dialogFormVisiblePackagingmaterials.value = false;
            }
        })
        .catch(err => {
            console.log(err);
        })
}
//图片
const bPImage = reactive({
    imageUrl: "",
    productionBatches: form.productionBatches,
    // traceabilityId: form.traceabilityId,
    // cultivationId: '',
    // slaughterId: '',
    // processingId: '',
    // enterpriseId: '',
    // rawmaterialId: '',
    // accessoriesId: '',
    // additiveId: '',
    packagingmaterialsId: '',
    createName: localStorage.getItem("userName"),
    createTime: new Date(),
})
//添加添加剂图片
const handlePictureCardPreviewBP = (url: any) => {
    // console.log(enterprise.enterpriseId)
    // console.log(qEImage.enterpriseId)
    bPImage.imageUrl = "http://localhost:24364" + url;
    axios.post("/api/Image/Create", bPImage)
        .then(res => {
            if (res.data.data == 1) {
                ElMessage.success("上传成功");
            }
        })
        .catch(err => {
            console.log(err);
        })
}
//显示添加剂图片
const bPimageList = ref([])
const getBPImageList = () => {
    // console.log(enterprise.enterpriseId)
    axios.get("/api/Image/GetPBImages?PackagingmaterialsId=" + packagingmaterials.packagingmaterialsId)
        .then(res => {
            bPimageList.value = res.data.data
        })
        .catch(err => {
            console.log(err);
        })
}
//#endregion

//#endregion

//#region 企业
    //企业信息
    const enterprise = reactive({
        enterpriseId: 0,
        farms: "",
        head: "",
        herdsNum: '',
        enterpriseName: "",
        provinceId: '',
        cityId: '',
        countyId: '',
        provinceName: '',
        cityName: '',
        countyName: '',
        founded: "",
        companyProfile: "",
        productionLicenseCode: "",
        productionBatches: form.productionBatches,
        tuZaiDate: "",
        createName: localStorage.getItem("userName"),
        createTime: new Date(),
        updateName: localStorage.getItem("userName"),
        updateTime: new Date(),
    })
    //打开企业对话框
    const showAdd = () => {
        dialogFormVisible1.value = true;
    }
    //企业校验(养殖)
    const rules8 = reactive<FormRules>({
        farms: [
            { required: true, message: '养殖场不能为空', trigger: 'blur', },
            { min: 0, max: 30, message: '最多输入30位字符', trigger: 'blur' },
        ],
        head: [
            { required: true, message: '负责人不能为空', trigger: 'blur', },
            { min: 0, max: 30, message: '最多输入30位字符', trigger: 'blur' },
        ],
        herdsNum: [
            { required: true, message: '存栏数量不能为空', trigger: 'blur', },
            { min: 0, max: 5, message: '最多输入5位数字', trigger: 'blur' },
            { type: 'number', message: "只允许输入数字" }
        ]
    })
    //添加企业(养殖)
    const addEnterprise = async (formEl: FormInstance | undefined) => {
        if (!formEl) return
        await formEl.validate((valid, fields) => {
            if (valid) {
                axios.post("/api/Enterprise/Create", enterprise)
                    .then(res => {
                        if (res.data.code == 0) {
                            ElMessage.success("添加成功");
                            dialogFormVisible1.value = false
                        }
                    })
                    .catch(err => {
                        console.log(err);
                    })
            } else {
                console.log('error submit!', fields)
            }
        })

    }
    //根据生产批次显示企业信息
    const showEnterprise = () => {
        axios.get("/api/Enterprise/GetEnterprise", {
            params: {
                ProductionBatches: form.productionBatches
            }
        })
            .then(res => {
                enterprise.enterpriseId = res.data.data.enterpriseId
                enterprise.farms = res.data.data.farms
                enterprise.head = res.data.data.head
                enterprise.herdsNum = res.data.data.herdsNum
                enterprise.enterpriseName = res.data.data.enterpriseName
                getProvinceList();
                enterprise.provinceId = res.data.data.provinceId
                enterprise.provinceName = res.data.data.provinceName
                getCityList();
                enterprise.cityId = res.data.data.cityId
                enterprise.cityName = res.data.data.cityName
                getCountyList();
                enterprise.countyId = res.data.data.countyId
                enterprise.countyName = res.data.data.countyName
                enterprise.founded = res.data.data.founded
                enterprise.companyProfile = res.data.data.companyProfile
                enterprise.productionLicenseCode = res.data.data.productionLicenseCode
                enterprise.productionBatches = res.data.data.productionBatches
                enterprise.createName = res.data.data.createName
                enterprise.createTime = res.data.data.createTime
                enterprise.updateName = res.data.data.updateName
                enterprise.updateTime = res.data.data.updateTime
                qEImage.enterpriseId = res.data.data.enterpriseId
                // console.log(enterprise.enterpriseId)
                //返填企业图片
                getQeImageList();
            })
            .catch(err => {
                console.log(err);
            })
    }
    //返填企业
    const backfillEnterprise = () => {
        axios.get("/api/Enterprise/GetEnterpriseByBatch", {
            params: {
                ProductionBatches: form.productionBatches
            }
        })
            .then(res => {
                enterprise.enterpriseId = res.data.data.enterpriseId
                enterprise.farms = res.data.data.farms
                enterprise.head = res.data.data.head
                enterprise.herdsNum = res.data.data.herdsNum
                enterprise.enterpriseName = res.data.data.enterpriseName
                getProvinceList();
                enterprise.provinceId = res.data.data.provinceId
                enterprise.provinceName = res.data.data.provinceName
                getCityList();
                enterprise.cityId = res.data.data.cityId
                enterprise.cityName = res.data.data.cityName
                getCountyList();
                enterprise.countyId = res.data.data.countyId
                enterprise.countyName = res.data.data.countyName
                enterprise.founded = res.data.data.founded
                enterprise.tuZaiDate = enterprise.founded
                enterprise.companyProfile = res.data.data.companyProfile
                enterprise.productionLicenseCode = res.data.data.productionLicenseCode
                enterprise.productionBatches = res.data.data.productionBatches
                enterprise.createName = res.data.data.createName
                enterprise.createTime = res.data.data.createTime
                enterprise.updateName = res.data.data.updateName
                enterprise.updateTime = res.data.data.updateTime
                qEImage.enterpriseId = res.data.data.enterpriseId
                // console.log(enterprise.enterpriseId)
                //返填企业图片
                getQeImageList();
            })
            .catch(err => {
                console.log(err);
            })
    }

    //企业修改(屠宰)
    //打开修改企业弹框
    const showupdEnter = () => {
        dialogFormVisibleSlaughterUpdEnter1.value = true;
        getProvinceList();
    }
    //企业校验(屠宰)
    const rules9 = reactive<FormRules>({
        enterpriseName: [
            { required: true, message: '公司名称不能为空', trigger: 'blur', },
            { min: 0, max: 30, message: '最多输入30位字符', trigger: 'blur' },
        ],
        countyId: [
            { required: true, message: '公司地址不能为空', trigger: 'blur', }
        ],
        founded: [
            { required: true, message: '成立时间不能为空', trigger: 'blur', },
            // { min: 0, max: 5, message: '最多输入5位数字', trigger: 'blur' },
            // { type: 'number', message: "只允许输入数字" }
        ],
        companyProfile: [
            { required: true, message: '公司简介不能为空', trigger: 'blur', },
            { min: 0, max: 30, message: '最多输入500位字符', trigger: 'blur' },
        ],
    })
    //修改企业
    const updEnter = async (formEl: FormInstance | undefined) => {
        if (!formEl) return
        await formEl.validate((valid, fields) => {
            if (valid) {
                axios.post("/api/Enterprise/UpdateEnterprise", enterprise)
                    .then(res => {
                        if (res.data.code == 0) {
                            ElMessage.success("添加成功");
                            dialogFormVisibleSlaughterUpdEnter1.value = false;
                            backfill();
                        }
                    })
                    .catch(err => {
                        console.log(err);
                    })
            } else {
                console.log('error submit!', fields)
            }
        })

    }

    //企业修改(深加工)
    //打开修改企业弹框
    const showupdEnter1 = () => {
        dialogFormVisibleSlaughterUpdEnter2.value = true;
        getProvinceList();
    }
    //企业校验(深加工)
    const rules10 = reactive<FormRules>({
        enterpriseName: [
            { required: true, message: '公司名称不能为空', trigger: 'blur', },
            { min: 0, max: 30, message: '最多输入30位字符', trigger: 'blur' },
        ],
        productionLicenseCode: [
            { required: true, message: '生产许可证号不能为空', trigger: 'blur', },
            { min: 0, max: 30, message: '最多输入30位字符', trigger: 'blur' },
        ],
    })
    //修改企业
    const updEnter1 = async (formEl: FormInstance | undefined) => {
        if (!formEl) return
        await formEl.validate((valid, fields) => {
            if (valid) {
                axios.post("/api/Enterprise/UpdateEnterprise", enterprise)
                    .then(res => {
                        if (res.data.code == 0) {
                            ElMessage.success("添加成功");
                            dialogFormVisibleSlaughterUpdEnter2.value = false;
                        }
                    })
                    .catch(err => {
                        console.log(err);
                    })
            } else {
                console.log('error submit!', fields)
            }
        })

    }

    //获取省份
    const provinceList: any = ref([])
    const getProvinceList = () => {
        axios.get("/api/Province/GetProvinceinfo")
            .then(res => {
                provinceList.value = res.data.data
            })
            .catch(err => {
                console.log(err);
            })
    }
    //获取城市
    const cityList: any = ref([])
    const getCityList = () => {
        enterprise.cityId = ''
        axios.get("/api/City/GetCityinfo?provinceId=" + (enterprise.provinceId || 0))
            .then(res => {
                cityList.value = res.data.data
            })
            .catch(err => {
                console.log(err);
            })
    }
    //获取县城
    const countyList: any = ref([])
    const getCountyList = () => {
        enterprise.countyId = ''
        axios.get("/api/County/GetCountyinfo?cityId=" + (enterprise.cityId || 0))
            .then(res => {
                countyList.value = res.data.data
            })
            .catch(err => {
                console.log(err);
            })
    }
//#endregion

//#region 图片
//企业图片
const qEImage = reactive({
    imageUrl: "",
    productionBatches: form.productionBatches,
    // traceabilityId: form.traceabilityId,
    // cultivationId: '',
    // slaughterId: '',
    // processingId: '',
    enterpriseId: '',
    // rawmaterialId: '',
    // accessoriesId: '',
    // additiveId: '',
    // packagingmaterialsId: '',
    createName: localStorage.getItem("userName"),
    createTime: new Date(),
})
//添加企业图片
const handlePictureCardPreviewQe = (url: any) => {
    // console.log(enterprise.enterpriseId)
    // console.log(qEImage.enterpriseId)
    qEImage.imageUrl = "http://localhost:24364" + url;
    axios.post("/api/Image/Create", qEImage)
        .then(res => {
            if (res.data.data == 1) {
                ElMessage.success("上传成功");
            }
        })
        .catch(err => {
            console.log(err);
        })
}
//显示企业图片
const qeimageList = ref([])
const getQeImageList = () => {
    // console.log(enterprise.enterpriseId)
    axios.get("/api/Image/GetQImages?EnterpriseId=" + enterprise.enterpriseId)
        .then(res => {
            qeimageList.value = res.data.data
            // console.log(qeimageList.value)
        })
        .catch(err => {
            console.log(err);
        })
}
//移除图片
const handleRemove: UploadProps['onRemove'] = (uploadFile: any) => {
    // console.log(uploadFile)
    axios.post("/api/Image/Delete?imageUrl=" + uploadFile.url)
        .then(res => {
            if (res.data.code == 0) {
                ElMessage.success("删除成功");
            }
        })
        .catch(err => {
            console.log(err);
        })
}

//产检图片
const simage = reactive({
    imageUrl: "",
    productionBatches: form.productionBatches,
    traceabilityId: form.traceabilityId,
    // cultivationId: '',
    // slaughterId: '',
    // processingId: '',
    // rawmaterialId: '',
    // accessoriesId: '',
    // additiveId: '',
    // packagingmaterialsId: '',
    createName: localStorage.getItem("userName"),
    createTime: new Date(),
})

//添加产检图片
const handlePictureCardPreview = (url: any) => {
    // console.log(form.traceabilityId)
    // console.log(simage.traceabilityId)
    simage.imageUrl = "http://localhost:24364" + url;
    axios.post("/api/Image/Create", simage)
        .then(res => {
            if (res.data.data == 1) {
                ElMessage.success("上传成功");
            }
        })
        .catch(err => {
            console.log(err);
        })
}
//显示产检图片
const simageList = ref([])
const getImageList = (traceabilityId: any) => {
    axios.get("/api/Image/GetAllImages?TraceabilityId=" + traceabilityId)
        .then(res => {
            simageList.value = res.data.data
            console.log(res.data.data)
        })
        .catch(err => {
            console.log(err);
        })
}
//#endregion

onMounted(() => {
    backfill();
})
</script>